#include "Block.h"

void Block::Place(XY Pos)
{
	//Worlds job to add to grid here
	//if(addBlockat())
	//then{
		Moving = false;
		m_CurrentPos = &Pos;
	//	Characters Job to remove form inventory here
	//	returns true now}
	//else{If this returns false it was not placed}
}

void Block::Destroy()
{
	m_Health.TakeHit(MAX_HEALTH);
	m_CurrentPos = XY(0,0);
	m_MovingToPos = XY(0,0);
	Moving = false;
}

void Block::Drop()
{
	//Need
	//XY FindNearestGround(XY);
	//SetNewDestination(FindNearestGround(m_CurrentPos));
}

bool Block::Move()
{

#ifdef _VERSION1_
	if(Moving)
	{
		//Move as needed
		if(m_CurrentPos.X < m_MovingToPos.X)
			m_CurrentPos.X++;
		if(m_CurrentPos.X > m_MovingToPos.X)
			m_CurrentPos.X--;
		if(m_CurrentPos.Y < m_MovingToPos.Y)
			m_CurrentPos.Y++;
		if(m_CurrentPos.Y > m_MovingToPos.Y)
			m_CurrentPos.Y--;

		//Check if still needing to move
		if(m_CurrentPos == m_MovingToPos)
			Moving = false;
		return true;
	}
#endif

	return false;
}

void Block::Update()
{
	Move();
	if(m_Health.CheckHealth() == -1) Destroy();
	else m_Health.Update();
}

void Block::SetNewDestination(XY NewPos)
{
	if(NewPos != m_CurrentPos)
		m_MovingToPos = &NewPos;
}